﻿<?php
/*
 * 添加孩子
 * 1、得到openid
 * 2、通过openid检索用户
 * 3、用户存在，跳转到用户中心
 * 4、用户不存在，跳转到注册
 */
require_once '../init.php';
define('TEMPLATE_PATH', WANYA_ROOT . '/m/view/');

$User_Info_Model = new User_Info_Model();
$User_Master_Model = new User_Master_Model();

// 孩子的信息
$childData = array();
$childData["nickname"] = $_POST['nickname'];
$childData["birthday"] = $_POST["birthday"];
$childData["sex"] = $_POST["sex"];
$childData["school"] = $_POST["school"];
$childData["identify_label"] = 5;
$childData["head_img_url"] = $_POST['head_img_url'];
$childData["is_main_account"] = 1;
// 家长的信息
$identifyLabel = $_POST["identifyLabel"];
$openid = $_POST["openid"];
echo $openid;
$userInfo = $User_Info_Model->getUserInfo($openid);
var_dump($userInfo);
$childData["family_id"] = $userInfo["family_id"];
var_dump($childData);
$User_Info_Model->addUserInfo($childData);


// 编辑家长的属性
$userData = array();
$userData["uid"] = $userInfo["uid"];
$userData["identify_label"] = $_POST["identify_label"];
var_dump($userData);
$User_Info_Model->updateUserInfo($userData);


// TODO 编辑家长的 identify_label
//$head_img_url =$userData["head_img_url"];

// 跳转个人中心页面
header("Location: https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx74e5910c0ad82aa1&redirect_uri=http%3A%2F%2Fmmgame.u7wan.cn%2Fwanya%2Fm%2FuserCenter.php&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect");
//确保重定向后，后续代码不会被执行
exit;
/*
include View::getView('user/userRegSuccess');
View::output();*/
?>
